import { HeroService } from './../hero.service';
import { Hero } from './../hero';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {

  heroes: Hero[] = []

  constructor(private heroService: HeroService) { }

  getHeroes(){
     this.heroService.getHeroes().subscribe(
        // slice 可以对数组操作，左闭右开，(1,5)表示取1-4个元素(英雄)
        heroes => this.heroes = heroes.slice(1,5)
     )
  }

  ngOnInit(): void {

     this.getHeroes()
  }

}
